package com.xjc.business.controller.sysadmin;

import com.xjc.business.entity.po.sysadmin.SetAddPo;
import com.xjc.business.entity.vo.SetVo;
import com.xjc.business.service.SetsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-01-26 7:54
 */
@RestController("sys_school_set_controller")
@RequestMapping("/sys_admin/set")
public class SchoolSetController {

    @Autowired
    SetsService setsService;

    /**
     * 获取所有套餐信息
     * @return 套餐信息
     */
    @GetMapping("/list")
    public Result<List<SetVo>> getSetList(){
        return setsService.getSetList();
    }

    /**
     * 添加套餐
     * @param setAddPo 套餐信息
     * @return 信息
     */
    @PostMapping("/add")
    public Result<String> addSet(@RequestBody(required = false) SetAddPo setAddPo){
        if(setAddPo == null || setAddPo.getSetName() == null || setAddPo.getSetName().equals("")){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return setsService.addSet(setAddPo);
    }

    /**
     * 删除套餐
     * @param id id
     * @return  信息
     */
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteSet(@PathVariable(value = "id",required = false) Integer id){
        if(id == null || id <= 0){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return setsService.deleteSet(id);
    }
}
